using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Library.DataTier.Compiled;

namespace OR.Lazarus.Library.DataTier.Compiled.Lazarus
{
	/// <summary>
	/// Defines a value within a DataRow for a specific Field.
	/// </summary>
   public class DataValueDetail : EntityBase
   {
		protected System.String mName;
		protected System.String mField;
		protected System.String mValue;
		protected string mDescription;

		public DataValueDetail()
		{
	
		}
	
		/// <summary>
		/// 
		/// </summary>
		public System.String Name
		{
			get
			{
				return ( mName );
			}
			set
			{
				mName = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public System.String Field
		{
			get
			{
				return ( mField );
			}
			set
			{
				mField = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public System.String Value
		{
			get
			{
				return ( mValue );
			}
			set
			{
				mValue = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Description
		{
			get
			{
				return ( mDescription );
			}
			set
			{
				mDescription = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mName = DataUtility.GetString( pSource, "name" );
			mField = DataUtility.GetString( pSource, "field" );
			mValue = DataUtility.GetString( pSource, "value" );
			XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "lzc:description", PersistenceConfig.Namespaces );
			
			if ( vDescription != null )
			{
				mDescription = vDescription.InnerText;
			}
			
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "lzc", "data-value", "http://schemas.icitadel.com/Lazarus/Compiled.xsd" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mName ) )
			{
				vNewElement.SetAttribute( "name", mName );
			}
					
			if ( !String.IsNullOrEmpty( mField ) )
			{
				vNewElement.SetAttribute( "field", mField );
			}
					
			if ( !String.IsNullOrEmpty( mValue ) )
			{
				vNewElement.SetAttribute( "value", mValue );
			}
					
			if ( !String.IsNullOrEmpty( mDescription ) )
			{
				XmlElement	vDescription = p_docContext.CreateElement( "lzc", "description", "http://schemas.icitadel.com/Lazarus/Compiled.xsd" );
				vDescription.InnerText = mDescription;
				vNewElement.AppendChild( vDescription );
			}
					

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.DataValueDetail v_oReturn = new Derived.DataValueDetail();
			
			v_oReturn.Name = mName;
			v_oReturn.Field = mField;
			v_oReturn.Value = mValue;
			v_oReturn.Description = mDescription;
			
			// FK Values

			// Collections
			
			return ( v_oReturn );
		}

		public virtual Derived.DataValueDetail CloneTyped()
		{
			return ( ( Derived.DataValueDetail )this.Clone() );
		}
   }
}
   